home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / Getleft / getleft-setup-notcl.exe / {app} / scripts / balloon.tcl < prev    next >
Encoding:
Text File  |  2004-02-21  |  3.8 KB  |  138 lines

  1. ##############################################################################
  2. # balloon.tcl - procedures used by balloon help
  3. #
  4. # Copyright (C) 1996-1997 Stewart Allen
  5. # This is part of vtcl source code
  6. # Adapted for general purpose by 
  7. # Daniel Roche <daniel.roche@bigfoot.com>
  8. # thanks to D. Richard Hipp for the multi-headed display fix
  9. # version 1.2 ( Sep 21 2000 ) 
  10. #
  11. # Modified 15-Nov-2000 by Andres Garcia <fandom@retemail.es>
  12. #     - Wrapped it up in a namespace.
  13. #     - Added the 'delete_balloon' procedure to unbind a 
  14. #       widget to a balloon.
  15. #
  16. # Modified 14-Jan-01 by Andres Garcia <fandom@retemail.es>
  17. #     - Added a <destroy> binding to the Bulle class so
  18. #       that if a widget that has a balloon gets destroyed
  19. #       the balloon won't survive it.
  20. #
  21. # Modified 14-Aug-01 by Andres Garcia <fandom@reteamil.es>
  22. #     - I made sure there can be no balloon when going to
  23. #       show one.
  24. #
  25. # Modified 30-Aug-01 by Andres Garcia <fandom@reteamil.es>
  26. #     - The coordinates where the balloon is going to be shown
  27. #       get modified by the <Motion> event between entering the
  28. #       widget and the moment where the balloon is shown.
  29. #     - Put more vertical and less horizontal distance between
  30. #       the cursor and the balloon. Mainly because the hourglass
  31. #       in Windows would cover the balloon.
  32. #
  33. # This program is free software; you can redistribute it and/or
  34. # modify it under the terms of the GNU General Public License
  35. # as published by the Free Software Foundation; either version 2
  36. # of the License, or (at your option) any later version.
  37. #
  38. # This program is distributed in the hope that it will be useful,
  39. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  41. # GNU General Public License for more details.
  42. #
  43. # You should have received a copy of the GNU General Public License
  44. # along with this program; if not, write to the Free Software
  45. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46. ##############################################################################
  47.  
  48. namespace eval BalloonHelp {
  49.  
  50. bind Bulle <Enter> {
  51.     set BalloonHelp::Bulle(x) %X
  52.     set BalloonHelp::Bulle(y) %Y
  53.     set BalloonHelp::Bulle(id) \
  54.             [after 500 {BalloonHelp::balloon %W}]
  55. }
  56.  
  57. bind Bulle <Leave> {
  58.     BalloonHelp::kill_balloon
  59. }
  60.  
  61. bind Bulle <Motion> {
  62.     set BalloonHelp::Bulle(x) %X
  63.     set BalloonHelp::Bulle(y) %Y
  64. }
  65.  
  66. bind Bulle <Button> {
  67.     BalloonHelp::kill_balloon
  68. }
  69.  
  70. bind Bulle <Destroy> {
  71.     BalloonHelp::delete_balloon %W
  72. }
  73.  
  74. proc set_balloon {target message} {
  75.     variable Bulle
  76.  
  77.     if {![info exists Bulle($target)]} {
  78.         bindtags $target "[bindtags $target] Bulle"
  79.     } else {
  80.         if {![string match $Bulle($target) $message]} {
  81.             catch {destroy .balloon}
  82.         }
  83.     }
  84.     set Bulle($target) $message
  85.  
  86.    return
  87. }
  88.  
  89. proc delete_balloon {target} {
  90.     variable Bulle
  91.  
  92.     if {![info exists Bulle($target)]} {
  93.         return
  94.     }
  95.     after cancel Bulle(id) 
  96.     unset Bulle($target)
  97.     set bindList   [bindtags $target]
  98.     set bulleIndex [lsearch $bindList Bulle]
  99.     set bindList   [lreplace $bindList $bulleIndex $bulleIndex]
  100.     bindtags $target $bindList
  101.  
  102.     catch {destroy .balloon}
  103.  
  104.     return
  105. }
  106.  
  107. proc kill_balloon {} {
  108.     variable Bulle
  109.  
  110.     after cancel $Bulle(id)
  111.     catch {destroy .balloon}
  112.  
  113.     return
  114. }
  115.  
  116. proc balloon {target} {
  117.     variable Bulle
  118.  
  119.     if {[catch {set Bulle($target)} message]} return
  120.     catch {destroy .balloon}
  121.  
  122.     set x $Bulle(x)
  123.     set y [expr {$Bulle(y) + 20}]
  124.  
  125.     toplevel .balloon -bg black -screen [winfo screen $target]
  126.     wm overrideredirect .balloon 1
  127.     label .balloon.l \
  128.             -text $message -relief flat \
  129.             -bg #ffffaa -fg black -padx 2 -pady 0 -anchor w
  130.     pack .balloon.l -side left -padx 1 -pady 1
  131.     wm geometry .balloon +${x}+${y}
  132.  
  133.     return
  134. }
  135.  
  136. }
  137.